home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / libcryp.c < prev    next >
C/C++ Source or Header  |  1997-07-27  |  991b  |  48 lines

  1. /*
  2. *                libCryp.c
  3. *
  4. * Library of encryption (std) for Citadel.
  5. */
  6. /*
  7. *                history
  8. *
  9. * 91????? HAW    Hash moved to Tools.c.
  10. * 87Aug06 HAW  Hash added.
  11. * 85Nov15 HAW  Created.
  12. */
  13. #include "ctdl.h"
  14. /*
  15. *                contents
  16. *
  17. *    crypte()        encrypts/decrypts data blocks
  18. */
  19. extern CONFIG cfg;        /* Configuration variables      */
  20. /*
  21. * crypte()
  22. *
  23. * encrypts/decrypts data blocks
  24. *
  25. * This was at first using a full multiply/add pseudo-random sequence
  26. * generator, but 8080s don't like to multiply.  Slowed down I/O
  27. * noticably.  Rewrote for speed.
  28. *
  29. * 84Sep04 HAW  I'll just use it......
  30. */
  31. void crypte(void *buf, unsigned len, unsigned seed)
  32.   {
  33.   static AN_UNSIGNED *b;      /* Make this static for speed (I guess),*/
  34.   static  int c, s;        /* since register variables not around  */
  35.   if( cfg.cryptSeed == 0 ) return;
  36.   seed    = (seed + cfg.cryptSeed) & 0xFF;
  37.   b        = (AN_UNSIGNED *) buf;
  38.   c        = len;
  39.   s        = seed;
  40.   for (;  c;  c--)
  41.     {
  42.     *b++   ^= s;
  43.     s       = (s + CRYPTADD)  &  0xFF;
  44.     
  45.     }
  46.   
  47.   }
  48.